home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch1 / Bars3.frm (.txt) < prev    next >
Visual Basic Form  |  1999-03-15  |  2KB  |  58 lines

  1. VERSION 5.00
  2. Begin VB.Form frmBars3 
  3.    Caption         =   "Bars3"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12. Attribute VB_Name = "frmBars3"
  13. Attribute VB_GlobalNameSpace = False
  14. Attribute VB_Creatable = False
  15. Attribute VB_PredeclaredId = True
  16. Attribute VB_Exposed = False
  17. Option Explicit
  18. Private Const NUM_VALUES = 7
  19. Private DataValue(1 To NUM_VALUES) As Integer
  20. ' Set the form's Scale properties.
  21. Private Sub SetTheScale(ByVal obj As Object, ByVal upper_left_x As Single, ByVal upper_left_y As Single, ByVal lower_right_x As Single, ByVal lower_right_y As Single)
  22.     obj.ScaleLeft = upper_left_x
  23.     obj.ScaleTop = upper_left_y
  24.     obj.ScaleWidth = lower_right_x - upper_left_x
  25.     obj.ScaleHeight = lower_right_y - upper_left_y
  26. End Sub
  27. ' Create some random data.
  28. Private Sub Form_Load()
  29. Dim i As Integer
  30.     Randomize
  31.     For i = 1 To NUM_VALUES
  32.         DataValue(i) = Rnd * 100
  33.     Next i
  34. End Sub
  35. ' Draw the bar chart.
  36. Private Sub Form_Paint()
  37. Dim i As Integer
  38. Dim wid As Single
  39. Dim hgt As Single
  40.     ' Define the custom coordinate system.
  41.     SetTheScale Me, 0, 110, NUM_VALUES + 2, -10
  42.     ' Clear the form.
  43.     Cls
  44.     ' Draw the bar chart.
  45.     For i = 1 To NUM_VALUES
  46.         ' Pick a new fill style.
  47.         FillStyle = i Mod 8
  48.         ' Draw a box with i <= X <= i + 1 and
  49.         ' 0 <= Y <= Data(i).
  50.         Line (i, 0)-(i + 1, DataValue(i)), , B
  51.     Next i
  52.     ' Draw a 5 by 5 pixel box at position
  53.     ' (NUM_VALUES / 2 + 1, 50).
  54.     wid = ScaleX(5, vbPixels, ScaleMode)
  55.     hgt = ScaleY(5, vbPixels, ScaleMode)
  56.     Line (NUM_VALUES / 2 + 1, 50)-Step(wid, hgt), vbRed, BF
  57. End Sub
  58.